local skill = fk.CreateSkill{
  name = "tea__lizang"
}
---@type TrigSkelSpec<TrigFunc>
local lizang = {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skill.name) and target.phase == Player.Finish and player:getMark("tea__lizang_canuse-turn") > 0 and not target.dead
     and not target:isNude()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local suits = {}
    while not player.dead and not target.dead do
      if target:isNude() or #suits >= 4 or #(table.filter(target:getCardIds("h"), function(id) return not target:prohibitDiscard(Fk:getCardById(id)) end) or {}) == 0 then break end
      local cid1 = room:askToDiscard(target, {
        min_num = 1,
        max_num = 1,
        skill_name = skill.name,
        include_equip = true,
        pattern = ".",
        prompt = "#tra_lizang-discard",
        skip = true,
      })
      if #cid1 > 0 then
        table.insertIfNeed(suits, Fk:getCardById(cid1[1]):getSuitString())
        if table.contains(target:getCardIds(Player.Hand), cid1[1]) and #target:getCardIds(Player.Hand) == 1 then
          room:throwCard(cid1[1], self.name, target, target)
          break
        else
          room:throwCard(cid1[1], self.name, target, target)
        end
      end
      if player:isNude() or #suits >= 4 or #(table.filter(player:getCardIds("h"), function(id) return not player:prohibitDiscard(Fk:getCardById(id)) end) or {}) == 0 then break end
      local cid2 = room:askToDiscard(player, {
        min_num = 1,
        max_num = 1,
        skill_name = skill.name,
        include_equip = true,
        pattern = ".",
        prompt = "#tra_lizang-discard",
        skip = true,
      })
      if #cid2 > 0 then
        table.insertIfNeed(suits, Fk:getCardById(cid2[1]):getSuitString())
        if table.contains(player:getCardIds(Player.Hand), cid2[1]) and #player:getCardIds(Player.Hand) == 1 then
          room:throwCard(cid2[1], self.name, player, player)
          break
        else
          room:throwCard(cid2[1], self.name, player, player)
        end
      end
    end 
  end,
}
---@type TrigSkelSpec<TrigFunc>
local lizang_re = {
  can_refresh = function(self, event, target, player, data)
    return target and player:hasSkill(self, true)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "tea__lizang_canuse-turn", 1)
  end,
}
skill:addEffect(fk.EventPhaseStart, lizang)
skill:addEffect(fk.EnterDying, lizang_re)
return skill